package cn.tedu.huntingmall.controller;

import cn.tedu.huntingmall.commons.response.JsonResult;
import cn.tedu.huntingmall.pojo.dto.shoppingcart.ShoppingCartAddNewDTO;
import cn.tedu.huntingmall.pojo.vo.shoppingcart.ShoppingCartAddNewVO;
import cn.tedu.huntingmall.pojo.vo.shoppingcart.ShoppingCartStandardVO;
import cn.tedu.huntingmall.service.IShoppingCartService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
@Api(tags = "购物车管理模块")
public class ShoppingCartController {

    @Autowired
    private IShoppingCartService service;

    @GetMapping("/addnew")
    @ApiOperation("购物车添加功能")
    @ApiOperationSupport(order = 10)
    public JsonResult<ShoppingCartAddNewVO> addNew(ShoppingCartAddNewDTO shoppingCartAddNewDTO){
        Long id = service.insert(shoppingCartAddNewDTO);
        return JsonResult.ok(new ShoppingCartAddNewVO().setId(id));
    }

    @GetMapping("/delete")
    @ApiOperation("购物车删除功能")
    @ApiOperationSupport(order = 20)
    public JsonResult delete(Long id, String username){
        int delete = service.delete(id, username);
        return JsonResult.ok(delete);
    }

    @GetMapping("/selete")
    @ApiOperation("查询用户购物车信息")
    @ApiOperationSupport(order = 40)
    public JsonResult<List<ShoppingCartStandardVO>> selectByUsername(String username){
        List<ShoppingCartStandardVO> shoppingCartList = service.selectByUsername(username);
        return JsonResult.ok(shoppingCartList);
    }
}
